package 方法的引用;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class 引用构造方法 {
    public static void main(String[] args) {
        //创建集合对象
        ArrayList<String> list=new ArrayList<>();
        Collections.addAll(list,"张无忌,15","周芷若,14","赵敏,13",
                "张强,20","张三丰,100","张翠山,40","张良,35","王二麻子,37");

        //匿名内部类
        list.stream().map(new Function<String, Student>() {
            @Override
            public Student apply(String s) {
                String name=s.split(",")[0];
                int age = Integer.parseInt(s.split(",")[1]);
                return new Student(name,age);

            }
        }).forEach(System.out::println);

        //引用构造方法
        List<Student> collect = list.stream().map(Student::new).toList();
        System.out.println(collect);
    }
}
